﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using Ebada.UI.Base;
using Ebada.Client;
using Ebada.Core;
using Ebada.Client.Platform;
namespace Ebada.Modules.Document
{
    /// <summary>
    /// 借出单证编辑
    /// </summary>
    public partial class frmDocumentBorrowOutEdit : FormBase, IPopupFormEdit 
    {
       
        SortableSearchableBindingList<Empolyees> m_OrgID = new SortableSearchableBindingList<Empolyees>();
        SortableSearchableBindingList<DocumentPosition> m_Position = new SortableSearchableBindingList<DocumentPosition>();
        //当借出时间改变时修改归还时间为借出时间加30天
        private double limitDays = 30;
        public frmDocumentBorrowOutEdit()
        {
            InitializeComponent();
        }
        void dataBind() {

                      
            this.btnOutusername.DataBindings.Add("EditValue", rowData, "OutUserName");
            this.dateOutDate.DataBindings.Add("EditValue", rowData, "OutDate");
            this.textOutPosition.DataBindings.Add("EditValue", rowData, "OutPosition");
            this.dateInDateLimit.DataBindings.Add("EditValue", rowData, "InDateLimit");
            this.memoCheckDes.DataBindings.Add("EditValue", rowData, "CheckDes");
        }
        #region IPopupFormEdit Members
        private DocumentMoveInfo rowData = null;

        public object RowData {
            get {
                return rowData;
            }
            set {
                if (value == null) return;
                if (rowData == null) {
                    this.rowData = value as DocumentMoveInfo;
                    InitComboBoxData(rowData.OutPosition);
                    dataBind();
                   
                } else {
                    ConvertHelper.CopyTo<DocumentMoveInfo>(value as DocumentMoveInfo, rowData);
                }
            }
        }

        #endregion

       
        private void InitComboBoxData(string OrgId)
        {
            this.m_Position.Clear();
            this.m_Position.Add(ClientHelper.PlatformSqlMap.GetList<DocumentPosition>(" WHERE 2>1"));
            this.SetComboBoxData(this.textOutPosition, "PositionName", "DocumentPositionID", "请选择", "库存位置", this.m_Position);

           
        }
        public void SetComboBoxData(DevExpress.XtraEditors.LookUpEdit comboBox, string displayMember, string valueMember, string nullTest, string cnStr, SortableSearchableBindingList<DocumentPosition> post)
        {
            comboBox.Properties.Columns.Clear();
            comboBox.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            comboBox.Properties.DataSource = post;
            comboBox.Properties.DisplayMember = displayMember;
            comboBox.Properties.ValueMember = valueMember;
            comboBox.Properties.NullText = nullTest;
            comboBox.Properties.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(valueMember, "ID", 20, DevExpress.Utils.FormatType.None, "", false, DevExpress.Utils.HorzAlignment.Default),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(displayMember, cnStr)});
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="comboBox"></param>
        /// <param name="displayMember"></param>
        /// <param name="valueMember"></param>
        /// <param name="nullTest"></param>
        /// <param name="cnStr"></param>
        /// <param name="post"></param>
      

        public string  Operator_Text
        {
            set { groupControlOrg.Text = value; }
        }

        private void txtCnFullName_EditValueChanged(object sender, EventArgs e)
        {

        }

       

        private void btnOutusername_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Ebada.Client.Platform.Selector.frmEmpSelectorByOrgInfo frm = new Ebada.Client.Platform.Selector.frmEmpSelectorByOrgInfo();
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.InitionData(string.Format(" where 1=1", this.btnOutusername.Text), false, false);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                btnOutusername.Text = frm.CurrentEmp.Empolyee_Name;
                rowData.OutUserID = frm.CurrentEmp.Empolyee_ID;
            
            }
              
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (btnOutusername.Text.Length==0)
            {
                MessageBox.Show("必须添写借出人！");
                btnOutusername.Focus();
                return;
            }
            else
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
      
        private void dateOutDate_EditValueChanged(object sender, EventArgs e)
        {

            dateInDateLimit.DateTime = dateOutDate.DateTime.AddDays(limitDays);
        }

       
        
       
       
    }
}